package com.wenya.counter;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import com.wenya.counter.data.bean.ScriptureBean;
import com.wenya.counter.data.db.CounterDatabase;

import java.util.ArrayList;
import java.util.List;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        CounterDatabase.initial(this);
        initData();
    }

    @SuppressLint("ApplySharedPref")
    private void initData() {
        SharedPreferences sharedPreferences = getSharedPreferences("config.xml", Context.MODE_PRIVATE);
        if (!sharedPreferences.getBoolean("dataWrite", false)) {
            sharedPreferences.edit().putBoolean("dataWrite", true).commit();
            if (CounterDatabase.getInstance().basicDataDao().selectCount() <= 0) {
                List<ScriptureBean> list = new ArrayList<>();
                ScriptureBean scriptureBean = new ScriptureBean();
                scriptureBean.setName("大悲咒");
                scriptureBean.setDivisor(27);
                list.add(scriptureBean);
                scriptureBean = new ScriptureBean();
                scriptureBean.setName("心经");
                scriptureBean.setDivisor(49);
                list.add(scriptureBean);
                scriptureBean = new ScriptureBean();
                scriptureBean.setName("往生咒");
                scriptureBean.setDivisor(84);
                list.add(scriptureBean);
                scriptureBean = new ScriptureBean();
                scriptureBean.setName("七佛灭罪真言");
                scriptureBean.setDivisor(87);
                list.add(scriptureBean);
                CounterDatabase.getInstance().basicDataDao().insert(list);
            }
        }
    }
}
